<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

	function __construct()
        {
		parent::__construct();
		$this->load->model('Users');
	}
	
	public function index()
	{
		$this->load->view('layout/header');
		$this->load->view('layout/menu');
		$this->load->view('layout/login');
		$this->load->view('layout/footer');
	}
	
	function validate()
        {            
            
		$var = $this->Users->ValidateSession($this->input->post());
	    
		if($var != 0)
			{
				$this->session->set_userdata($var);
				$string = $this->lang->lang() . "/login/main";
				echo json_encode($string);				
			}
			else
			{
			    echo json_encode(false);
			}
			
        }
        
	function main()
        {
            if($this->session->userdata('logged_in'))
                {
			//obtener los datos para armar el menu
			$data['menu'] = $this->Users->load_menu($this->session->userdata('gpoId'));
			//------------------------------------
			$this->load->view('layout/header');
			$this->load->view('layout/menu',$data);
			$this->load->view('system/inbox');
			$this->load->view('layout/footer');
                }
                else
                {
                    redirect("/");
                }
        }
	
        function LogOut()
        {
            $var = array('user_data' => null,'username' => null,'email' => null, 'logged_in' => false);
            $this->session->set_userdata($var);
            $this->session->unset_userdata(null);
            $this->session->sess_destroy();
            redirect($this->lang->lang()."/");    
        }
	
}
